package com.tronsis.distribution.activity.me.complaints;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.tronsis.distribution.R;
import com.tronsis.distribution.biz.factory.CommonFactory;
import com.tronsis.library.activity.ToolBarBaseActivity;
import com.tronsis.library.http.UICallBack;
import com.tronsis.library.util.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ComplainingActivity extends ToolBarBaseActivity {

    @BindView(R.id.et_reason)
    EditText mEtReason;
    @BindView(R.id.et_description)
    EditText mEtDescription;
    @BindView(R.id.btn_submit)
    Button mBtnSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_complaining);
        ButterKnife.bind(this);
        setTitle(true, getString(R.string.complaints));

    }

    @OnClick(R.id.btn_submit)
    void submitClick() {
        String reason = mEtReason.getText().toString();
        String description = mEtDescription.getText().toString();

        if (TextUtils.isEmpty(reason)) {
            ToastUtil.showMessage(mContext, "请输入投诉原因");
            return;
        }

        if (TextUtils.isEmpty(description)) {
            ToastUtil.showMessage(mContext, "请输入投诉描述");
            return;
        }

        httpSubmitReport(reason, description);
    }

    private void httpSubmitReport(String reason, String description) {
        try {
            CommonFactory.createBiz().submitReport(this, description, reason, new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    ToastUtil.showMessage(mContext,"投诉提交成功");
                    dismissLoadingDialog();
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();

                }
            });
        } catch (Exception e) {
            dismissLoadingDialog();
            e.printStackTrace();
        }
    }
}
